local hx__fenwei = fk.CreateSkill {
  name = "hx__fenwei",
  tags = { Skill.Limited },

}

hx__fenwei:addEffect(fk.TargetSpecified, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__fenwei.name) and data.firstTarget and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
      return player:usedSkillTimes(hx__fenwei.name, Player.HistoryGame) == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = {"hx__fenwei_target", "hx__fenwei_more"}
    local choose = room:askToChoice(player, {
      choices = choice,
      skill_name = hx__fenwei.name,
    })
    local x = #room:getAlivePlayers()
    local y = player.maxHp - player.hp
    if choose == "hx__fenwei_target" then
      local tos = player.room:askToChoosePlayers(player ,{
        targets = data.use.tos,
        min_num = 1,
        max_num = 999,
        skill_name = hx__fenwei.name,
        prompt = "#hx__fenwei-choose-remove:::"..data.card:toLogString(),
        cancelable = true,
      })
      data.use.nullifiedTargets = data.use.nullifiedTargets or {}
      table.insertTableIfNeed(data.use.nullifiedTargets, tos)
      local targets2 = table.filter(room:getAlivePlayers(), function(p)
        return not p.dead and not table.contains(data.use.tos, p)
      end)
      local newTargets = player.room:askToChoosePlayers(player ,{
        min_num = 1,
        max_num = x,
        targets = targets2,
        skill_name = hx__fenwei.name,
        prompt = "#hx__fenwei-choose",
        cancelable = true,
      })
      if #newTargets > 0 then
        for _, id in ipairs(newTargets) do
          data:addTarget(id)
        end
      end
    elseif choose == "hx__fenwei_more" then
      data.use.additionalEffect = (data.use.additionalEffect or 0) + y
    end
  end,
})

return hx__fenwei